package com.googlecode.imanager.client.style;

import java.io.Serializable;

import com.googlecode.imanager.client.bridge.style.IFont;
import com.googlecode.imanager.client.util.Utils;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class Font implements IFont, Serializable {

    private static final long serialVersionUID = 1L;
    
    public static final Font EMPTY_FONT = new Font(null, null, 
            Color.BLACK, false, false, false, false, HorzAlignment.DEFAULT, VertAlignment.DEFAULT);

    private String name;
    private Integer size;
    private Color color;
    private Boolean bold;
    private Boolean italic;
    private Boolean underline;
    private Boolean strike;
    private HorzAlignment horzAlignment;
    private VertAlignment vertAlignment;

    public Font(String name) {
        super();
        this.name = name;
    }

    public Font(Integer size, Color color) {
        super();
        this.size = size;
        this.color = color;
    }

    public Font(String name, Integer size, Color color) {
        super();
        this.name = name;
        this.size = size;
        this.color = color;
    }

    public Font(HorzAlignment horzAlignment, VertAlignment vertAlignment) {
        super();
        this.horzAlignment = horzAlignment;
        this.vertAlignment = vertAlignment;
    }

    public Font(String name, Integer size, Color color,
            HorzAlignment horzAlignment, VertAlignment vertAlignment) {
        super();
        this.name = name;
        this.size = size;
        this.color = color;
        this.horzAlignment = horzAlignment;
        this.vertAlignment = vertAlignment;
    }

    public Font(Boolean bold, Boolean italic, Boolean underline, Boolean strike) {
        super();
        this.bold = bold;
        this.italic = italic;
        this.underline = underline;
        this.strike = strike;
    }

    public Font(String name, Integer size, Color color, Boolean bold,
            Boolean italic, Boolean underline, Boolean strike) {
        super();
        this.name = name;
        this.size = size;
        this.color = color;
        this.bold = bold;
        this.italic = italic;
        this.underline = underline;
        this.strike = strike;
    }

    public Font(String name, Integer size, Color color, Boolean bold,
            Boolean italic, Boolean underline, Boolean strike,
            HorzAlignment horzAlignment, VertAlignment vertAlignment) {
        super();
        this.name = name;
        this.size = size;
        this.color = color;
        this.bold = bold;
        this.italic = italic;
        this.underline = underline;
        this.strike = strike;
        this.horzAlignment = horzAlignment;
        this.vertAlignment = vertAlignment;
    }

    public String getName() {
        return name;
    }

    public Integer getSize() {
        return size;
    }

    public Color getColor() {
        return color;
    }

    public Boolean getBold() {
        return bold;
    }

    public Boolean getItalic() {
        return italic;
    }

    public Boolean getUnderline() {
        return underline;
    }

    public Boolean getStrike() {
        return strike;
    }

    public HorzAlignment getHorzAlignment() {
        return horzAlignment;
    }

    public VertAlignment getVertAlignment() {
        return vertAlignment;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this){
            return true;
        }
        if (obj instanceof Font){
            Font f = (Font) obj;
            return Utils.isEquals(name, f.name)
                && Utils.isEquals(size, f.size)
                && Utils.isEquals(color, f.color)
                && Utils.isEquals(bold, f.bold)
                && Utils.isEquals(italic, f.italic)
                && Utils.isEquals(underline, f.underline)
                && Utils.isEquals(strike, f.strike)
                && Utils.isEquals(horzAlignment, f.horzAlignment)
                && Utils.isEquals(vertAlignment, f.vertAlignment);
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        
        if (name != null){
            hash ^= name.hashCode();
        }
        if (size != null){
            hash ^= size.hashCode();
        }
        if (color != null){
            hash ^= color.hashCode();
        }
        if (bold != null){
            hash ^= bold.hashCode();
        }
        if (italic != null){
            hash ^= italic.hashCode();
        }
        if (underline != null){
            hash ^= underline.hashCode();
        }
        if (strike != null){
            hash ^= strike.hashCode();
        }
        if (horzAlignment != null){
            hash ^= horzAlignment.hashCode();
        }
        if (vertAlignment != null){
            hash ^= vertAlignment.hashCode();
        }

        return hash;
    }

    @Override
    public String toString() {
        StringBuilder value = new StringBuilder();
        value.append("Font[");
        boolean next = false;
        
        if (name != null){
            next = true;
            value.append("name=").append(name);
        }
        if (size != null){
            if (next){
                value.append(", ");
            } else {
                next = true;
            }
            value.append("size=").append(size);
        }
        if (color != null){
            if (next){
                value.append(", ");
            } else {
                next = true;
            }
            value.append("color=").append(color);
        }
        if (bold != null){
            if (next){
                value.append(", ");
            } else {
                next = true;
            }
            value.append("bold=").append(bold);
        }
        if (italic != null){
            if (next){
                value.append(", ");
            } else {
                next = true;
            }
            value.append("italic=").append(italic);
        }
        if (underline != null){
            if (next){
                value.append(", ");
            } else {
                next = true;
            }
            value.append("underline=").append(underline);
        }
        if (strike != null){
            if (next){
                value.append(", ");
            } else {
                next = true;
            }
            value.append("strike=").append(strike);
        }
        if (horzAlignment != null){
            if (next){
                value.append(", ");
            } else {
                next = true;
            }
            value.append("horzAlignment=").append(horzAlignment);
        }
        if (vertAlignment != null){
            if (next){
                value.append(", ");
            }
            value.append("vertAlignment=").append(vertAlignment);
        }
        
        value.append(']');
        return value.toString();
    }    
   
}
